package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ReturnPresent;
import com.qj.yantaishan.service.IReturnPresentService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 退货赠品Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ReturnPresent")
public class ReturnPresentController extends BaseController
{
    private String prefix = "yantaishan/ReturnPresent";

    @Autowired
    private IReturnPresentService returnPresentService;

    @RequiresPermissions("yantaishan:present:view")
    @GetMapping()
    public String present()
    {
        return prefix + "/present";
    }

    /**
     * 查询退货赠品列表
     */
    @RequiresPermissions("yantaishan:present:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReturnPresent returnPresent)
    {
        startPage();
        List<ReturnPresent> list = returnPresentService.selectReturnPresentList(returnPresent);
        return getDataTable(list);
    }

    /**
     * 导出退货赠品列表
     */
    @RequiresPermissions("yantaishan:present:export")
    @Log(title = "退货赠品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReturnPresent returnPresent)
    {
        List<ReturnPresent> list = returnPresentService.selectReturnPresentList(returnPresent);
        ExcelUtil<ReturnPresent> util = new ExcelUtil<ReturnPresent>(ReturnPresent.class);
        return util.exportExcel(list, "退货赠品数据");
    }

    /**
     * 新增退货赠品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存退货赠品
     */
    @RequiresPermissions("yantaishan:present:add")
    @Log(title = "退货赠品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReturnPresent returnPresent)
    {
        return toAjax(returnPresentService.insertReturnPresent(returnPresent));
    }

    /**
     * 修改退货赠品
     */
    @RequiresPermissions("yantaishan:present:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReturnPresent returnPresent = returnPresentService.selectReturnPresentById(id);
        mmap.put("returnPresent", returnPresent);
        return prefix + "/edit";
    }

    /**
     * 修改保存退货赠品
     */
    @RequiresPermissions("yantaishan:present:edit")
    @Log(title = "退货赠品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReturnPresent returnPresent)
    {
        return toAjax(returnPresentService.updateReturnPresent(returnPresent));
    }

    /**
     * 删除退货赠品
     */
    @RequiresPermissions("yantaishan:present:remove")
    @Log(title = "退货赠品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(returnPresentService.deleteReturnPresentByIds(ids));
    }
}
